function Line (start, end) {
    this.start = start;
    this.end = end;
}

Line.prototype = {
    constructor: Line,
    getLength: function () {
        var x1 = this.start.x, y1 = this.start.y, x2 = this.end.x ,y2 = this.end.y;
        return Math.sqrt((x1 -= x2)*x1 + (y1 -= y2)*y1);
    },
    getIntersection: function(line){
        var pt1Dir = new Point(this.end.x - this.start.x, this.end.y - this.start.y);
        var pt2Dir = new Point(line.end.x - line.start.x, line.end.y - line.start.y);
        var det = (pt1Dir.x * pt2Dir.y) - (pt1Dir.y * pt2Dir.x);
        var deltaPt = new Point(line.start.x - this.start.x, line.start.y - this.start.y);
        var alpha = (deltaPt.x * pt2Dir.y) - (deltaPt.y * pt2Dir.x);
        var beta = (deltaPt.x * pt1Dir.y) - (deltaPt.y * pt1Dir.x);

        if (det === 0 || alpha * det < 0 || beta * det < 0){
            return null;
        }

        if (det > 0){
            if (alpha > det || beta > det){
                return null;
            }
        } else {
            if (alpha < det || beta < det){
                return null;
            }
        }
        return new Point(this.start.x + (alpha * pt1Dir.x / det), this.start.y + (alpha * pt1Dir.y / det));
    }
}